# 从文件kaifanglist.txt中获取数据
# 题目： 开房查询
# 	创建函数，传入一个名字，查找到这哥们所有的开房记录，
#           然后写入到以这哥们名字为名的txt文件中 如：张三.txt
#

"""
def fn(name):
    '''
    :param name: 被查找人的名字
    :return: 无
    '''

    f = open('kaifanglist.txt','r')
    content = f.readlines()
    g = open(f'{name}.txt', 'a')

    for line in content:
        line_list = line.split(',')
        for x in line_list:
            if name == x:
                g.write(line)
    g.flush()
    g.close()
    f.close()


fn('陈伟')
"""


def fn(name):
    f = open('kaifanglist.txt', 'r')
    content = f.readlines()

    for row in content:
        li1 = row.split(',')
        if name == li1[0]:
            with open(f'{name}.txt', 'a', encoding='utf-8') as fp:
                fp.write(row)


fn('陈伟')
